package com.ncr.travel.appmgr.service.provider.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.ncr.travel.appmgr.model.ThemeInfoJson;
import com.ncr.travel.appmgr.model.ThemeJson;
import com.ncr.travel.appmgr.model.shared.Theme;
import com.ncr.travel.appmgr.service.provider.ThemeProvider;

/**
 * @author as185325
 * 
 */
@Component
public class ThemeProviderImpl implements ThemeProvider {

	private static final Logger logger = LoggerFactory.getLogger(ThemeProviderImpl.class);

	private static final String MOCK_THEME_UUID = "2290af2a-44b8-4c82-b63f-97314aa1d9ef";
	private static final String MOCK_THEME_NAME = "theme1";
	private static final String MOCK_THEME_VERSION = "1.0";

	/*private MockDatabase mockDataBase;

	@Autowired
	public ThemeProviderImpl(MockDatabase mockDataBase) {
		this.mockDataBase = mockDataBase;
	}*/

	/**
	 * @see com.ncr.travel.appmgr.service.provider.com.ncr.travel.appmgr.service.provider.ThemeProvider#getThemeByUUID(java.lang.String)
	 */
	@Override
	public Theme getThemeByUUID(String themeId) {
		UUID.fromString(themeId);
		if (MOCK_THEME_UUID.equals(themeId)) {
			// return mockDataBase.getTheme();
			return null;
		} else {
			return null;
		}
	}

	/**
	 * @see com.ncr.travel.appmgr.service.provider.com.ncr.travel.appmgr.service.provider.ThemeProvider#getThemeByNameVersion(java.lang.String, java.lang.String)
	 */
	@Override
	public Theme getThemeByNameVersion(String themeName, String version) {
		if (MOCK_THEME_NAME.equals(themeName) && MOCK_THEME_VERSION.equals(version)) {
			// return mockDataBase.getTheme();
			return null;
		} else {
			return null;
		}
	}

	/**
	 * @see com.ncr.travel.appmgr.service.provider.com.ncr.travel.appmgr.service.provider.ThemeProvider#getThemes()
	 */
	@Override
	public List<Theme> getThemes() {

		List<Theme> themesList = new ArrayList<Theme>();

		try {

			ThemeJson theme = new ThemeJson();
			theme.setId(UUID.randomUUID().toString());
			theme.setName("AppManagerThemeName1");
			theme.setVersion("1.0");

			ThemeInfoJson themeInfo = new ThemeInfoJson();

			themeInfo.setProperty("styleSheet", "/ui/themes/styles/calendar.css");
			themeInfo.setProperty("image", "/ui/themes/images/next.jpg");
			theme.setThemeInfo(themeInfo);

			themesList.add(theme);

			theme = new ThemeJson();
			theme.setId(UUID.randomUUID().toString());
			theme.setName("AppManagerThemeName2");
			theme.setVersion("2.0");

			themeInfo.setProperty("styleSheet", "/ui/themes/styles/appmanager.css");
			themeInfo.setProperty("image", "/ui/themes/images/appmanagerlogo.jpg");
			theme.setThemeInfo(themeInfo);

			themesList.add(theme);
		} catch (NullPointerException e) {
			String errMesg = "Error in fetching list of themes: " + e;
			System.out.println(e.toString());
			logger.error(errMesg, e);

		} catch (Exception e) {
			String errMesg = "Error in fetching list of themes: " + e;
			System.out.println(e.toString());
			logger.error(errMesg, e);

		}
		return themesList;

	}
}
